<?php

class vueEdit{
	
	public static function form(){
		
		$tpl = new Template("tpl/editeur/");
		$tpl->set_file("page","authent.tpl");
		
		if (isset($_SESSION['message'])){
			$tpl->set_var("MESSAGE",$_SESSION['message']);
			unset($_SESSION['message']);
		}
		
		$tpl->parse("PAGE","page");
		return $tpl->get("PAGE");
		
	}
	
	public static function affiche(){
		
		$tpl = new Template("tpl/editeur");
		$tpl->set_file("page","editeur.tpl");
		
		$tpl->set_block("page","block_journaux","journaux");
		$tpl->set_block("page","block_publicites","pub");
		$tpl->set_block("page","block_journ","journ");
		
		if (isset($_SESSION['message'])){
			$tpl->set_var('MESSAGE',$_SESSION['message']);
			unset($_SESSION['message']);
		}
		
		$editeur = Session::getInstance()->getEditeur();
		$journaux = Journal::getJournauxEditeur($editeur->getIDEditeur());
		
		foreach ($journaux as $journal){
			$tpl->set_var("JOURN_ID",$journal->getIDJournal());
			$tpl->set_var("JOURN_NAME", $journal->getNom());
			$tpl->parse("journ","block_journ",true);
		}
		
		// Remplissage des journaux
		foreach ($journaux as $journal){
			$editions = Edition::recupAllLastSeven($journal->getIDJournal());
			foreach ($editions as $ed){
				$tpl->set_var("NOM_JOURNAL",$journal->getNom());
				$tpl->set_var("DATE",$ed->getDate());
				$tpl->parse("journaux","block_journaux",true);
			}
		}
		
		
		// Remplissage des pubs
		
		foreach ($journaux as $journal){
			$publicites = Publicite::getPubJournal($journal->getIDJournal());
			foreach ($publicites as $pub){
				$tpl->set_var("SRC",$pub->getURL());
				$tpl->parse("pub","block_publicites",true);
			}
		}
		
		
		$tpl->parse("PAGE","page");
		return $tpl->get("PAGE");
		
	}
	
	
}
?>